package com.guess.lolguessing.service.impl;

import com.guess.lolguessing.domain.po.UserPoints;
import com.guess.lolguessing.mapper.UserPointsMapper;
import com.guess.lolguessing.service.IUserPointsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2024-10-24
 */
@Service
public class UserPointsServiceImpl extends ServiceImpl<UserPointsMapper, UserPoints> implements IUserPointsService {

    @Override
    public int getPointsByUserId(Long userId) {
        UserPoints one = this.lambdaQuery().eq(UserPoints::getUserId, userId).one();
        return one.getPoints();
    }

    @Override
    public void updatePointsByUserId(Long userId, int amount) {
        UserPoints one = this.lambdaQuery().eq(UserPoints::getUserId, userId).one();
        one.setPointsId(one.getPoints() - amount);
        this.updateById(one);
    }
}
